<!--
 * @Description: 查看弹框
 * @Author: Huang Junjie
 * @Date: 2021-06-24 19:41:24
 * @LastEditTime: 2021-07-28 17:58:39
 * @LastEditors: Liu Zhiwang
-->
<template>
  <div>
    <base-dialog
      width="90%"
      class="home-todo-list-dialog"
      :visible.sync="dialog.visible"
      :title="dialog.title"
      :show-default-footer="false"
    >
      <div class="todo-list-dialog__title">
        <p class="todo-list-dialog__title-text">{{ getRiskWarning(dialog.index).title }}</p>
        <p class="todo-list-dialog__title-time">下发日期：{{ parseTime(getRiskWarning(dialog.index).updateTime, '{y}-{m}-{d}') }}</p>
      </div>
      <div class="todo-list-dialog__wrapper">
        <el-scrollbar>
          <div class="todo-list-dialog__text" v-html="getRiskWarning(dialog.index).detail" />
        </el-scrollbar>
      </div>
      <div v-if="getRiskWarning(dialog.index).attachments && getRiskWarning(dialog.index).attachments.length" class="file-down" @click="handleDownload(getRiskWarning(dialog.index))">附件下载 <i class="el-icon-download" type="small" /></div>
      <div slot="footer" class="todo-list-dialog__footer">
        <div class="todo-list-dialog__prev">
          <div class="todo-list-dialog__prev-text" :title="getRiskWarning(dialog.index - 1).title">
            {{ getRiskWarning(dialog.index - 1).title }}
          </div>
          <el-button
            type="text"
            class="todo-list-dialog__prev-btn"
            :disabled="!dialog.index"
            @click="dialog.index--"
          >上一条</el-button>
        </div>
        <div class="todo-list-dialog__next">
          <el-button
            type="text"
            class="todo-list-dialog__next-btn"
            :disabled="dialog.index === dialog.list.length - 1"
            @click="dialog.index++"
          >下一条</el-button>
          <div class="todo-list-dialog__next-text" :title="getRiskWarning(dialog.index + 1).title">
            {{ getRiskWarning(dialog.index + 1).title }}
          </div>
        </div>
      </div>
    </base-dialog>
  </div>
</template>

<script>
import { parseTime } from '@/utils';
import { downloadFile } from '@/utils/public';

export default {
  props: {
    // 弹框配置
    dialog: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  methods: {
    parseTime,

    getRiskWarning(index) {
      return this.dialog.list[index] || {};
    },

    handleDownload(item) {
      var params = {
        url: item.attachments[0].path,
        fileName: item.attachments[0].fileName
      };
      downloadFile(params).then((response) => {});
    }
  }
};
</script>

<style lang="scss" scoped>
.home-todo-list-dialog{
  /deep/.el-dialog{
    background: #122854;
    .el-dialog__header{
      background: #122854;
      border-bottom-color: #3585d2;
    }
    .el-dialog__body{
      color: #fff;
      height: calc(90vh - 120px);
      position: relative;
    }
  }
  /deep/.is-fullscreen .el-dialog__body{
    height: calc(100vh - 103px);
  }
  .todo-list-dialog__title{
    text-align: center;
    &-text{
      font-size: 28px;
      padding: 0 30px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    &-time{
      font-size: 22px;
      margin: 10px 0;
    }
  }
  .todo-list-dialog__wrapper{
    height: calc(100% - 77px);
    margin: 0 30px;
    border: 1px solid #3585d2;
    border-radius: 9px;
    font-size: 16px;
    line-height: 36px;
    /deep/.el-scrollbar__wrap{
      padding: 20px;
    }
  }
  .file-down {
    position: absolute;
    bottom: 0px;
    left: 28px;
    cursor: pointer;
    padding: 18px 34px 0;
    font-size: 16px;
    color: #409EFF;
    &:hover {
      color: #ffffff;
      text-decoration-line: underline;
    }
  }
  .todo-list-dialog__footer{
    display: flex;
    color: #ffffff;
    .todo-list-dialog__prev{
      flex: 1;
      display: flex;
      align-items: center;
      text-align: right;
      &-text{
        flex: 1;
        width: 0;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
    }
    .todo-list-dialog__next{
      flex: 1;
      display: flex;
      align-items: center;
      text-align: left;
      &-text{
        flex: 1;
        width: 0;
        text-align: left;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
    }
  }
}
</style>
